using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.IO;

namespace Meta
{
	/// <summary>
	/// Summary description for Help.
	/// </summary>
	public class HelpBrowser : System.Windows.Forms.Form
	{
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		ArrayList urlsVisited = new ArrayList();
//		int currentUrlIndex = -1;
		System.Object nullObject;
		string str;
		System.Object nullObjStr;
		private System.Windows.Forms.ImageList imageList1;
		private System.Windows.Forms.PrintDialog printDialog1;
		private System.ComponentModel.IContainer components;
		private PrintDocument printDoc = new PrintDocument();
//		private Font printFont;
		private AxSHDocVw.AxWebBrowser ManualBrowser;
//		private StreamReader streamToPrint;

		public HelpBrowser(string path) {
			// Objects necessary for the browser control.
			nullObject = 0;
			str = "";
			nullObjStr = str;
			
			// Necessary for Windows Designer support.
			ManualBrowser = new AxSHDocVw.AxWebBrowser();
			((System.ComponentModel.ISupportInitialize)(this.ManualBrowser)).BeginInit();
			InitializeComponent();
			this.ManualBrowser.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.ManualBrowser.Enabled = true;
			this.ManualBrowser.OcxState = null; //((System.Windows.Forms.AxHost.State)(resources.GetObject("ManualBrowser.OcxState")));
			this.ManualBrowser.Size = new System.Drawing.Size(775, 432);
			this.ManualBrowser.TabIndex = 2;
			this.Controls.Add(this.ManualBrowser);
			((System.ComponentModel.ISupportInitialize)(this.ManualBrowser)).EndInit();

			ManualBrowser.Navigate(path, ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr);
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(HelpBrowser));
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.printDialog1 = new System.Windows.Forms.PrintDialog();
			// 
			// mainMenu1
			// 
			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem1});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem2});
			this.menuItem1.Text = "File";
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 0;
			this.menuItem2.Text = "Exit";
			this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
			// 
			// imageList1
			// 
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// HelpBrowser
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.BackColor = System.Drawing.SystemColors.Control;
			this.ClientSize = new System.Drawing.Size(772, 433);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Menu = this.mainMenu1;
			this.Name = "HelpBrowser";
			this.Text = "Help";

		}
		#endregion

		private void menuItem2_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}

	public class HelpMenuItem : MenuItem {
		public HelpMenuItem(string name, string fileName) : base(name) {
			this.fileName = fileName;
		}
		public HelpMenuItem(string name, string fileName, Shortcut shortcut) :base(name) {
			this.fileName = fileName;
			this.Shortcut = shortcut;
		}
		string fileName;

		protected override void OnClick(EventArgs e) {
			base.OnClick (e);
			new HelpBrowser(fileName).Show();
		}
	}	

	public class HelpDirectoryMenuItem : MenuItem {
		public HelpDirectoryMenuItem(string name, string directoryPath) : base(name) {
			foreach (string path in System.IO.Directory.GetFiles(directoryPath)) {
				if (System.IO.Path.GetExtension(path)==".htm")
					this.MenuItems.Add(new HelpMenuItem(Path.GetFileNameWithoutExtension(path), path));
			}
		}
	}
}
